﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Mvc;
using HCQ2_Common;
using HCQ2_Common.Bean;
using HCQ2_Common.Constant;
using HCQ2_Model;
using HCQ2_Model.ViewModel;
using HCQ2_Model.ViewModel.SysAdmin;
using HCQ2_Model.SysUserModel;
using HCQ2_Common.Encrypt;
using System.IO;
using System.Diagnostics;

namespace HCQ2UI_Logic
{
    /// <summary>
    ///  系统设置 >异常管理
    /// </summary>
    public class SysExceptionController : BaseLogic
    {
        //*********************************用户管理*****************************************
        #region 1.0 首次进入日志页面 +ActionResult List()
        /// <summary>
        ///  首次进入日志页面
        /// </summary>
        /// <returns></returns>
        [HCQ2_Common.Attributes.Load]
        [HttpGet]
        public ActionResult List()
        {
            return View();
        }
        #endregion

        #region 1.1 获取日志列表 +ActionResult GetLogTable(QueryModel param) 
        /// <summary>
        ///  获取日志列表
        /// </summary>
        /// <param name="role"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult GetLogTable()
        {
            string logCode = RequestHelper.GetStrByName("log_code");//异常代码
            int rows = RequestHelper.GetIntByName("rows"),
                page = RequestHelper.GetIntByName("page"),
                total = 0;
            List<T_VRExceptionLog> list;
            if (!string.IsNullOrEmpty(logCode))
            {
                list = operateContext.bllSession.T_VRExceptionLog.Select(s => s.logCode.Equals(logCode));
                if (list.Count > 0)
                    total = 1;
            }else
            {
                list = operateContext.bllSession.T_VRExceptionLog.Select(s => true, s => s.requestDate, page, rows, false);
                total = operateContext.bllSession.T_VRExceptionLog.SelectCount(s => true);
            }
            TableModel tModel = new TableModel()
            {
                total = total,
                rows = list
            };
            return Json(tModel, JsonRequestBehavior.AllowGet);
        }
        #endregion

        #region 1.2 删除记录 +ActionResult DelLogById(int id)
        /// <summary>
        ///  删除记录
        /// </summary>
        /// <param name="id">用户id</param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult DelLogById(List<string> logCode)
        {
            if (logCode.Count <= 0)
                return operateContext.RedirectAjax(1, "需要删除的数据不存在~", "", "");
            logCode.ForEach(o => operateContext.bllSession.T_VRExceptionLog.Delete(s => s.logCode.Equals(o)));
            return operateContext.RedirectAjax(0, "数据删除成功~", "", "");
        }
        #endregion

        #region 1.3 标记已处理 +ActionResult DelLogById(int id)
        /// <summary>
        ///  标记已处理
        /// </summary>
        /// <param name="id">用户id</param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult SetHandleById(List<string> logCode)
        {
            if (logCode==null || logCode.Count <= 0)
                return operateContext.RedirectAjax(1, "需要删除的数据不存在~", "", "");
            T_VRExceptionLog log = new T_VRExceptionLog { handDate = DateTime.Now, isSolve = true };
            logCode.ForEach(o => operateContext.bllSession.T_VRExceptionLog.Modify(log, s => s.logCode.Equals(o), "handDate", "isSolve"));
            return operateContext.RedirectAjax(0, "记录标记成功~", "", "");
        }
        #endregion
    }
}